<?php if ( ! defined('BASEPATH')) exit('No direct script access allowed');

class UserDB extends ObjectMapDB {
	public $tableName = 'tbl_user';

	public function __construct() {
		parent::__construct($this->tableName);
		$this->isDebug = false;
	}

	/**
	 * public function insert($input)
	 * @return id | FALSE
	 * @param array $input
	 */

	/**
	 * public function update($input, $where)
	 * @return TRUE | FALSE
	 * @param array $input
	 * @param array $where
	 */

	/**
	 * public function delete($where)
	 * @return TRUE | FALSE
	 * @param array $where
	 */

	/**
	 * public function getById($id)
	 * @param int $id
	 * @param string $fields optional
	 * @return false || array 2D
	 */

	/**
	 * public function get($where) => get all array('id >' => 1)
	 * @param array $where
	 * @param string $fields optional
	 * @return false || array 2D
	 */

	// ==================================================
	/*
	 * Query Bindings
	 * $sql = "SELECT * FROM some_table WHERE id = ? AND status = ? AND author = ?";
	 * $this->db->query($sql, array(3, 'live', 'Rick'));
	 */

	// ==================================================
	/*
	 * trasaction
	 * $this->db->trans_begin();
	 * $this->db->query('AN SQL QUERY...');
	 * $this->db->query('ANOTHER QUERY...');
	 * $this->db->query('AND YET ANOTHER QUERY...');
	 *
	   	if ($this->db->trans_status() === FALSE) {
			$this->db->trans_rollback();
		} else {
			$this->db->trans_commit();
		}
	*/
	// ==================================================



	// here process logic business
	public function validInputForInsert() {

		// validation
		$this->form_validation->set_rules('email', 'Email', 'trim|required|valid_email');

		$this->form_validation->set_message('required', 'Error Message email required');
		$this->form_validation->set_message('valid_email', 'Error Message invalid email');

		$this->form_validation->set_rules('password', 'Password', 'trim|required');
		$this->form_validation->set_message('required', 'Error Message password required');

		$error_code = 0;
		$error_message = '';
		if ($this->form_validation->run() == FALSE) {
			// 			echo '<pre>';
			// 			print_r($this->form_validation);
			// 			echo '</pre>';

			if( strlen(form_error('email')) != 0 ) {
				$error_code = -100;
				$error_message = form_error('email');
			}
			if( strlen(form_error('pws')) != 0 )  {
				$error_code = -101;
				$error_message = form_error('pws');
			}

		}

		$this->load->library('webserviceresponse');
		$response = array('code' => $error_code, 'message' => $error_message, 'data' => '');
		$stringXml = $this->webserviceresponse->responseString($response, 'xml');
		return $this->load->view('xml', array('string' => $stringXml));
	}

}